

/**
    listModel转成js数组
  */
function listModelToJsArray(model, keys) {
    const jsonArray = []
    for (var i = 0; i < model.count; i++) {
        const element = {}
        for (let key of keys) {
            element[key] = model.get(i)[key]
        }
        jsonArray.push(element)
    }
    return jsonArray
}


/**
    model转成js对象
  */
function modelToJsObj(model, keys) {
    const element = {}
    for (let key of keys) {
        element[key] = model[key]
    }
    return element
}
function imgUrl(u, width, height) {
    if (u === null || u === '') {
        return ''
    }
    return `${u}?param=${width}y${height}`
}

function imgUrlAccurate(u, width, height) {
    if (u === null || u === '') {
        return ''
    }
    const logicalPixelDensity = Screen.logicalPixelDensity || 1
    width = Math.floor(width * logicalPixelDensity)
    height = Math.floor(height * logicalPixelDensity)
    return `${u}?param=${width}y${height}`
}


/**
  millisecond 毫秒 number
  */
function timeFormat(millisecond) {
    if (millisecond === null || millisecond === undefined) {
        return "00:00"
    }
    let second = Math.floor(millisecond / 1000)
    let minute = Math.floor(second / 60)
    second = second % 60
    if (second < 10) {
        second = "0" + second
    }
    if (minute < 10) {
        minute = "0" + minute
    }
    return `${minute}:${second}`
}
function dateFormat(millisecond, fmt = "yyyy-MM-dd hh:mm:ss") {
    if (millisecond === null || millisecond === undefined) {
        return ""
    }
    const date = new Date(millisecond)
    var o = {
        "M+": date.getMonth() + 1,
        "d+"//月份
        : date.getDate(),
        "h+"//日
        : date.getHours(),
        "m+"//小时
        : date.getMinutes(),
        "s+"//分
        : date.getSeconds(),
        "q+"//秒
        : Math.floor((date.getMonth() + 3) / 3),
        "S"//季度
        : date.getMilliseconds() //毫秒
    }
    if (fmt === null) {
        return date.toDateString()
    }
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(
                              4 - RegExp.$1.length))
    for (var k in o)
        if (new RegExp('(' + k + ')').test(fmt))
            fmt = fmt.replace(
                        RegExp.$1,
                        RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(
                                                     ('' + o[k]).length))
    return fmt
}
